Skip to content

Conversation

cngmid
Copy link
Contributor

@cngmid cngmid commented Aug 20, 2025

Reference Issues/PRs

Fixes #1930.

When time_idx or some other integer feature is included in the unknow reals, the dataset/dataloader elements are converted into the wrong dtype.

What does this implement/fix? Explain your changes.

Modify the function the method TimeSeriesDataSet._data_to_tensors._to_tensor()

What should a reviewer concentrate their feedback on?

Did you add any tests for the change?

Added test function to tests/test_data/test_timeseries.py

Any other comments?

PR checklist

  • [ x] The PR title starts with either [ENH], [MNT], [DOC], or [BUG]. [BUG] - bugfix, [MNT] - CI, test framework, [ENH] - adding or improving code, [DOC] - writing or improving documentation or docstrings.
  • [x ] Added/modified tests

Copy link

codecov bot commented Aug 20, 2025

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@6074011). Learn more about missing BASE report.

Files with missing lines Patch % Lines
pytorch_forecasting/data/timeseries/_timeseries.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1950   +/-   ##
=======================================
  Coverage        ?   87.21%           
=======================================
  Files           ?      142           
  Lines           ?     8865           
  Branches        ?        0           
=======================================
  Hits            ?     7732           
  Misses          ?     1133           
  Partials        ?        0           
Flag Coverage Δ
cpu 87.21% <80.00%> (?)
pytest 87.21% <80.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cngmid cngmid changed the title Fixing bug #1930 with proper syntax [BUG] Fixing bug #1930 with proper syntax Aug 20, 2025
elif isinstance(cols, list): # and len(cols) > 0
dtypekind = data.dtypes[cols[0]].kind
# dtypekind = data.dtypes[cols[0]].kind
dtypekind = data[cols].to_numpy().dtype.kind
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we doing this? It feels wasteful to do the conversion for the entire data container, instead of looking up the dtype.

Copy link
Collaborator

@fkiraly fkiraly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I have a question about to_numpy - should we not avoid conversion of the entire data to numpy?

@cngmid
Copy link
Contributor Author

cngmid commented Aug 25, 2025

Looks good, I have a question about to_numpy - should we not avoid conversion of the entire data to numpy?

Good point.

Would this be better?

dtypekind = np.result_type(*data[cols].dtypes.to_list()).kind

@fkiraly
Copy link
Collaborator

fkiraly commented Aug 25, 2025

Would this be better?

Yes, I think this would avoid the memory leak, since we never read the values

@cngmid
Copy link
Contributor Author

cngmid commented Aug 26, 2025

dtypekind = np.result_type(*data[cols].dtypes.to_list()).kind

I just pushed this change.

Copy link
Collaborator

@fkiraly fkiraly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, could you update the docstring?

@cngmid
Copy link
Contributor Author

cngmid commented Aug 27, 2025

great, could you update the docstring?

done and pushed through

@fkiraly fkiraly changed the title [BUG] Fixing bug #1930 with proper syntax [BUG] Fix TimeSeriesDataSet wrong inferred tensor dtype when time_idx is included in features Aug 27, 2025
Copy link
Collaborator

@fkiraly fkiraly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!

@fkiraly fkiraly merged commit 53f8cbd into sktime:main Aug 27, 2025
35 checks passed
@cngmid cngmid deleted the new-timeseries-branch branch August 27, 2025 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] TimeSeriesDataSet wrong dtype when time_idx is included
2 participants